package com.wiloon.java8x.math;

import java.math.BigDecimal;

public class MathTest {
    public static void main(String[] args) {
//        for (int i = 0; i < 100; i++) {
//           // System.out.println(new Random().nextInt());
//            System.out.println(Math.abs(new Random().nextInt())%2);
//            //System.out.println(Math.abs(new Random().nextInt()) % 1);
//        }
        MathTest.test();
    }

    public static void test() {
        System.out.println("四舍五入取整:(2)="
                + new BigDecimal("2").setScale(0, BigDecimal.ROUND_HALF_UP));

        System.out.println("四舍五入取整:(2.1)="
                + new BigDecimal("2.1").setScale(0, BigDecimal.ROUND_HALF_UP));

        System.out.println("四舍五入取整:(2.5)="
                + new BigDecimal("2.5").setScale(0, BigDecimal.ROUND_HALF_UP));

        System.out.println("四舍五入取整:(2.9)="
                + new BigDecimal("2.9").setScale(0, BigDecimal.ROUND_HALF_UP));

        System.out.println("math round:(2.933)="
                + Math.round(2.933));

        System.out.println("四舍五入取两位小数:(2.933)="
                + new BigDecimal("2.933").setScale(2, BigDecimal.ROUND_HALF_UP));

    }
}
